﻿namespace System.Data.Entity
{
    using System.Data.Entity.Infrastructure;
    using System.Data.Entity.ModelConfiguration.Conventions;

    /// <summary>
    /// Provides runtime information about a given <see cref="DbContext" /> type.
    /// </summary>
    public class FullTextContextInfo<TContext> : DbContextInfo
        where TContext : DbContext
    {
        /// <summary>
        /// Creates a new instance representing a given <see cref="DbContext" /> targeting a specific database.
        /// </summary>
        /// <param name="connectionInfo"> Connection information for the database to be used. </param>
        public FullTextContextInfo(string connectionString)
            : base(typeof(TContext), new DbConnectionInfo(connectionString, "System.Data.SqlClient"))
        {
            base.OnModelCreating = this.InternalOnModelCreating;
        }

        private void InternalOnModelCreating(DbModelBuilder modelBuilder)
        {
            //modelBuilder.HasDefaultSchema("dbo");

            modelBuilder.Conventions.Add(new FullTextIndexedTableAttributeConvention());
            modelBuilder.Conventions.Add(new FullTextIndexAttributeConvention());

            modelBuilder.Conventions.Add(new FullTextSearchConvention());
        }
    }
}
